package com.example.JavaWebApi.model.querymodel.SystemQueryModel;/**
 * @author: 杨泽
 * @create: 2022-04-13 13:38
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

/**
 *@program: adks.process-api
 *@description: 分页查询模型
 *@author: 杨泽
 *@create: 2022-04-13 13:38
 */
@Data
@ApiModel("分页查询模型")
public class PageQuery {
    @ApiModelProperty(value = "每页条数",position = 998)
    protected Integer limit=15;
    @ApiModelProperty(value = "页码",position = 999)
    protected Integer page=1;
    /**
     * Description: 根据条件字符串生成in条件
     * @param queryWrapper 条件构造器
     * @param conditionString 条件字符串
     * @param queryField 查询字段
     * @return void
     * @author 杨泽
     * @date 2023/8/22 16:28
     */
    public <T> void in(QueryWrapper<T> queryWrapper, String conditionString, String queryField){
        if(StringUtils.isNotBlank(conditionString)){
            String[] arr=conditionString.split(",");
            queryWrapper.in(queryField,arr);
        }
    }
    /**
     * Description: 根据条件字符串生成NotIn条件
     * @param queryWrapper 条件构造器
     * @param conditionString 条件字符串
     * @param queryField 查询字段
     * @return void
     * @author 杨泽
     * @date 2023/8/22 16:28
     */
    public <T> void notIn(QueryWrapper<T> queryWrapper,String conditionString,String queryField){
        if(StringUtils.isNotBlank(conditionString)){
            String[] arr=conditionString.split(",");
            queryWrapper.notIn(queryField,arr);
        }
    }
    @ApiModelProperty(hidden = true)
    public Pageable toPageable(){
        PageRequest pageRequest=PageRequest.of(page-1,limit);
        if(page<0||limit<0){
            pageRequest.isUnpaged();
        }
        return pageRequest;
    }
    /**
     * Description: 从另一个pageQuery里面复制page和limit参数
     *
     * @param pageQuery
     * @return void
     * @author 杨泽
     * @date 2023/8/4 11:09
     */
    public <T extends PageQuery> void copyPage(T pageQuery) {
        this.limit = pageQuery.getLimit();
        this.page = pageQuery.getPage();
    }

    public void notPage(){
        this.limit=-1;
        this.page=-1;
    }
}
